package face.pay.web.agency.user.controller;

import face.pay.system.annotation.CurrentUser;
import face.pay.constant.RoleCode;
import face.pay.constant.UserType;
import face.pay.entity.UserInfo;
import face.pay.util.ResultMessage;
import face.pay.util.page.PageData;
import face.pay.util.page.PageParam;
import face.pay.web.com.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping(value = "/agency_user")
public class AgencyUserController {

    @Autowired
    private IUserService iUserService;
    /**
     * 代理商用户
     * @return
     */
    @RequestMapping("/list")
    public String manager(){

        return  "agency/user/userList";
    }


    @RequestMapping("/queryData")
    @ResponseBody
    public PageData data(@CurrentUser UserInfo logUser,PageParam pageParam, UserInfo userInfo){

        userInfo.setType(UserType.AGENCY);
        userInfo.setDeleted(0);
        return  this.iUserService.queryPage(logUser,userInfo,pageParam);

    }

    /**
     * 代理商注册 （开下级代理）
     * @param userInfo
     * @return
     * @throws
     */
    @RequestMapping("/edit")
    @ResponseBody
    public ResultMessage editUser(UserInfo userInfo,@CurrentUser UserInfo logUser)  {

        /**
         * 设置默认的类型
         */
        userInfo.setType(UserType.AGENCY);
        userInfo.setDeleted(0);
        return  iUserService.editUser(logUser,RoleCode.ROLE_AGENCY_MANAGER,userInfo);

    }

}
